import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt

flag=cv.COLOR_BGR2HSV
flag2=cv.COLOR_BGR2GRAY
img=cv.imread('F:\\11\\caoshen.png',1)
img2=cv.cvtColor(img,flag)#图像色彩空间转换
cv.imshow('caoshen',img2)
img3=cv.cvtColor(img,flag2)

plt.imshow(img[:,:,::-1])
plt.title('caoshen'),plt.xticks([]),plt.yticks([])
plt.show()
#注意利用matplotlib输出灰度图的时候要写成
plt.imshow(img3,cmap=plt.cm.gray)
plt.title('caoshen'),plt.xticks([]),plt.yticks([])
plt.show()